# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer: Holger Jaekel <holger.jaekel@gmx.de>
pkgname=tiledb
pkgver=2.26.2
pkgrel=0
pkgdesc="Engine for storing and accessing dense and sparse multi-dimensional arrays"
url="https://tiledb.com/"
# Tests fail on s390x
# doesn't build on 32-bit
arch="all !armhf !armv7 !x86 !s390x"
license="MIT"
makedepends="
	abseil-cpp-dev
	blosc-dev
	bzip2-dev
	capnproto-dev
	catch2-3
	clang
	cmake
	crc32c-dev
	curl-dev
	doxygen
	file-dev
	google-cloud-cpp-dev
	libpng-dev
	lz4-dev
	nlohmann-json
	openssl-dev
	samurai
	spdlog-dev
	zlib-dev
	zstd-dev
	"
subpackages="
	$pkgname-dev
	"
source="tiledb-$pkgver.tar.gz::https://github.com/TileDB-Inc/TileDB/archive/refs/tags/$pkgver.tar.gz
	https://raw.githubusercontent.com/muellan/clipp/v1.2.3/include/clipp.h
	10-compression.patch
	70-avx2.patch
	80-test.patch
	"
builddir="$srcdir/TileDB-$pkgver"

# secfixes:
#   2.17.4-r0:
#     - CVE-2023-5129

# Optional dependencies aws-* are not available on s390x and ppc64le
_with_s3="OFF"
case "$CARCH" in
arm*|s390x|ppc64le) ;;
*)
# S3 support presently fails to build from source with current AWS SDK.
#	makedepends="$makedepends aws-crt-cpp-dev aws-sdk-cpp-dev"
#	_with_s3="ON"
	;;
esac

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		local crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	CXXFLAGS="$CXXFLAGS -Wno-deprecated-declarations" \
	LDFLAGS="$LDFLAGS -Wl,--copy-dt-needed-entries" \
	TILEDB_DISABLE_AUTO_VCPKG=OFF \
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_SHARED_LIBS=ON \
		-DCMAKE_SKIP_RPATH=ON \
		-DTILEDB_VERBOSE=OFF \
		-DTILEDB_HDFS=OFF \
		-DTILEDB_S3=$_with_s3 \
		-DTILEDB_AZURE=OFF \
		-DTILEDB_GCS=ON \
		-DTILEDB_SERIALIZATION=ON \
		-DTILEDB_TOOLS=OFF \
		-DTILEDB_WERROR=OFF \
		-DTILEDB_CPP_API=ON \
		-DTILEDB_STATS=ON \
		-DTILEDB_TESTS="$(want_check && echo ON || echo OFF)" \
		-DTILEDB_CCACHE=OFF \
		-DTILEDB_ARROW_TESTS=OFF \
		-DTILEDB_WEBP=OFF \
		$crossopts

	# compile Cap’n Proto schema with the current version
	cd "$builddir/tiledb/sm/serialization"
	capnp compile -oc++:. tiledb-rest.capnp
	cd "$builddir"

	cmake --build build
	if want_check; then
		cmake --build build --target tests
	fi
}

check() {
	ctest --output-on-failure --test-dir build \
		-R '^unit_|test_assert' -E 'unit_capi_query_plan|unit_capi_query_aggregate|unit_fragment|unit_aggregators|unit_vfs|unit_capi_current_domain|unit_capi_ndrectangle|unit_array_schema|unit_run_filter_pipeline'
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
0b623acf1d0aca59085ef1ac5138516738948d957eeb7b74d480ba0362ca0e18a3316306ea67cd5a27907c9be1464f76820a7178ba22aa6648f0d88399591c91  tiledb-2.26.2.tar.gz
0a801eff46581a96e571b41ce734d5a8e7f30333d46e3fb81c4c40fc44c18035d4b4597732221e37945ad23b94e53e496562ae4b24d358761dbf5ed803f66ff4  clipp.h
df27399a1b0ee6822d2438c1a06f4633b49eaaae98635675e82da94e99736d3fbc0db4dd1238251ac5859f99e5d6fe3ef713f613b4215045b7b1f1acfb9f14d5  10-compression.patch
86e5f9722e4ef8524b96d059ba434508cf03e3c264ec3bfcaf3585dae5584f4863e4bbc6f34be68e653df18cd7d827f8fc36b058acdc4636609412526bc95d5b  70-avx2.patch
3a22fdb4493cbe78b177dd1c749b1a364cd92a972f8d59a16a9417d9243da9e202d033a204b1d5512c47b4c601a8fdd7d9ec10b2a1c30993363a4d285103a67e  80-test.patch
"
